#!/bin/sh
TMPDIR=/usr/local/src/rtctools

OPENRTM_PYTHON=OpenRTM-aist-Python-1.0.0
OPENRTM_PYTHON_FILE=$OPENRTM_PYTHON-RELEASE.tar.gz
OPENRTM_PYTHON_URL=http://www.openrtm.org/pub/OpenRTM-aist/python/1.0.0/$OPENRTM_PYTHON_FILE

RTCTREE_URI=https://github.com/gbiggs/rtctree.git
RTSPROFILE_URI=https://github.com/gbiggs/rtsprofile.git
RTSHELL_URI=https://github.com/gbiggs/rtshell.git
RTMEXT_URI=https://github.com/hyaguchijsk/rtmext.git


if [ ! -e ${TMPDIR} ];
then
    mkdir -p $TMPDIR

    #install openrtm-aist-python
    cd $TMPDIR
    wget $OPENRTM_PYTHON_URL
    tar xvzf $OPENRTM_PYTHON_FILE
    cd $OPENRTM_PYTHON
    python setup.py build
    sudo python setup.py install

    #compile rtctree
    cd $TMPDIR
    git clone $RTCTREE_URI
    cd rtctree
    sudo python setup.py install

    #compile rtsprofile
    cd $TMPDIR
    git clone $RTSPROFILE_URI
    cd rtsprofile
    sudo python setup.py install

    #compile rtshell
    cd $TMPDIR
    git clone $RTSHELL_URI
    cd rtshell
    sudo python setup.py install

    cd $TMPDIR
    git clone $RTMEXT_URI

    #add something in .bashrc.rtm
    cat << EOF >> $HOME/.bashrc.rtm

#for rtcshell
export RTCTREE_NAMESERVERS=localhost
source /usr/local/share/rtshell/shell_support

#for rtmext
export PATH=\${PATH}:/usr/local/src/rtctools/rtmext
export RTM_PACKAGE_PATH=/usr/local/src/OpenRTM/OpenRTM-aist-1.0.0/examples
function rtmcd () {
    cd \`rtmpack find \$1\`
}
EOF

    echo "Setting for rtshell is done."
fi

